//
//  KDTopDayTableViewCell.m
//  KongDays
//
//  Created by deeplu on 13. 1. 3..
//  Copyright (c) 2013년 BlueBeans. All rights reserved.
//

#import "KDTopDayTableViewCell.h"
#import "NSDay.h"
#import <QuartzCore/QuartzCore.h>

@implementation KDTopDayTableViewCell

@synthesize day = day_;
@synthesize pictureImageView;
@synthesize titleLabel;
@synthesize dateLabel;
@synthesize countLabel;

- (void)dealloc
{
    [self.day release];
    [self.pictureImageView release];
    [self.titleLabel release];
    [self.dateLabel release];
    [self.countLabel release];
    
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.pictureImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.titleLabel.textColor = [UIColor whiteColor];
        self.titleLabel.backgroundColor = [UIColor clearColor];
        self.titleLabel.font = [UIFont boldSystemFontOfSize:30.0f];
        
        self.dateLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.dateLabel.backgroundColor = [UIColor clearColor];
        self.dateLabel.font = [UIFont boldSystemFontOfSize:20.0f];
        self.dateLabel.textColor = [UIColor whiteColor];
        
        self.countLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.countLabel.backgroundColor = [UIColor clearColor];
        self.countLabel.font = [UIFont boldSystemFontOfSize:70.0f];
        self.countLabel.textColor = [UIColor whiteColor];
        self.countLabel.textAlignment = NSTextAlignmentRight;
        
        [self.contentView addSubview:self.pictureImageView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.dateLabel];
        [self.contentView addSubview:self.countLabel];

    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    if (self.pictureImageView) {
        self.pictureImageView.frame = CGRectMake(0.0, 0.0, 300.0, 199.0);
        [self.contentView bringSubviewToFront:self.pictureImageView];
    }

    if (self.titleLabel) {
        self.titleLabel.frame = CGRectMake(10.0, 10.0, 280.0, 30.0);
        [self.contentView bringSubviewToFront:self.titleLabel];
    }
    
    if (self.dateLabel) {
        self.dateLabel.frame = CGRectMake(10.0, 43.0, 280.0, 20.0);
        [self.contentView bringSubviewToFront:self.dateLabel];
    }
    
    if (self.countLabel) {
        self.countLabel.frame = CGRectMake(10.0, 130.0, 280.0, 70.0);
        [self.contentView bringSubviewToFront:self.countLabel];
    }
}

- (void)bindDay:(NSDay *)day
{
    if (day == nil)
        return;
    
    self.day = day;
    
    self.pictureImageView.image = [UIImage imageNamed:@"holiday.png"];
    
    CALayer *layer = [pictureImageView layer];
    [layer setMasksToBounds:YES];
    [layer setCornerRadius:6.0f];
    
    self.titleLabel.text = self.day.title;
    self.dateLabel.text = [self.day dateToString];
    self.countLabel.text = self.day.daysCountText;
}

@end
